<?php
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
$input = $app->input;
$action = $input->get('action');

$itemid = $input->get('Itemid');
$items = $this->get('Items');
$this->pagination = $this->get('pagination');
$maxsize = $input->get('maxsize');
?>

<?php if ($action == 'create'): ?>
    <div class="res-title-rg">
        <span class="fl pos-icon text-c"><b class="glyphicon glyphicon-plus fontsize20"></b></span>
        <div class="title-info">
            <h2 class="fontsize20">Create an TestPhones</h2>
            <p><a href="#">Home</a>&nbsp;/&nbsp;Setup&nbsp;/&nbsp;Create an TestPhones</p>
        </div>
    </div>
    <div class="ws-content pdall15">
        <div style="width:600px;margin:auto">
            <div style="padding:32px 0 4px 0;text-align:right;font-size:18px;border-bottom:solid 2px #000">TestPhones Form</div>
            <div style="height:32px"></div>
            <form method="post" class="form-horizontal J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=TestPhones&action=store">
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">Imei</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="imei" name="imei" placeholder="input Imei">
                    </div>
                </div>
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">Device Id</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="device_id" name="device_id" placeholder="input Device Id">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default J_ajax_submit_btn">Create</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php elseif ($action == 'edit'): //表单?>
    <?php
    $model = $this->getModel();
    $Item = $model->getItem( (int) $input->get('id'));
    ?>
    <div class="ws-content pdall15">
        <div style="width:600px;margin:auto">
            <div style="padding:32px 0 4px 0;text-align:right;font-size:18px;border-bottom:solid 2px #000">TestPhones Form</div>
            <div style="height:32px"></div>
            <form method="post" class="form-horizontal J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=TestPhones&action=update">
                <input type="hidden" name="id" value="<?php echo $Item->id;?>">
                <div class="form-group">
                    <label for="name" class="col-sm-3 control-label">Imei</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="imei" name="imei" value="<?php echo $Item->imei;?>" placeholder="Imei">
                    </div>
                </div>
                <div class="form-group">
                    <label for="name" class="col-sm-3 control-label">Device Id</label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control" id="device_id" name="device_id" value="<?php echo $Item->device_id;?>"  placeholder="Device Id">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <a class="layer_confirm btn btn-danger" title="are you sure?" href="/index.php?option=com_console&Itemid=127&task=TestPhones&action=delete&id=<?php echo $Item->id?>">Delete&Close</a>
                        <button type="submit" class="btn btn-default J_ajax_submit_btn">Save&Close</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

<?php else: ?>
    <div class="res-title-rg">
        <span class="fl pos-icon text-c"><i class="setup"></i></span>
        <div class="title-info">
            <h2 class="fontsize20">TestPhones</h2>
            <p><a href="#">Home</a>&nbsp;/&nbsp;Setup&nbsp;/&nbsp;TestPhones</p>
        </div>
    </div>
    <div class="ws-content pdall15">
        <?php if($this->pagination->total <= $maxsize):?>
        <div class="camtab"><a href="/index.php?option=com_console&view=testphones&Itemid=127&task=TestPhones&action=create" class="fr btn-popup fontsize16">+&nbsp;Create an TestPhones</a></div>
       <?php endif;?>
        <form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
            <div style="padding:8px">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>Imei</th>
                        <th>Device Id</th>

                        <th>Operate</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if($items):?>
                    <?php foreach ($items as $key => $item): ?>
                        <tr>
                            <td><?php echo $item->imei ?></td>
                            <td><?php echo $item->device_id ?></td>
                            <td>
                                <a href="/index.php?option=com_console&view=testphones&Itemid=127&task=TestPhones&action=edit&id=<?php echo $item->id?>">Edit</a>&nbsp;
                            </td>
                        </tr>
                    <?php endforeach ?>
                    <?php endif; ?>
                    </tbody>
                </table>
                <?php // Add pagination links ?>
                <div class="pagination">
                    <?php echo $this->pagination->getPagesLinks(); ?>
                </div>
            </div>
        </form>
    </div>

<?php endif;?>
